package d5_stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class t1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        Collections.addAll(list, "acd", "adf", "cfa", "afff", "e", "f", "g", "h");
        Collections.sort(list);

//        List<String> list1 = new ArrayList<>();//老方法
//        for (String s : list) {//遍历
//            if(s.startsWith("a")&&s.length()==3) {//以什么开头，字符串长度
//                    list1.add(s);
//            }
//        }
//        System.out.println(list1);

        //stream
        List<String> list3=list.stream().filter(s -> s.startsWith("a")&&s.length()==3).collect(Collectors.toList());//获取Stream流 fileter方法 收集数据
        System.out.println(list3);


    }
}
